//
//  RecommendedCell.m
//  wedding
//
//  Created by 常宽 on 15/1/28.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

#import "RecommendedCell.h"
#import "GoodsModel.h" /// 传进来的数组里的数据

#define HEIGHT self.contentView.frame.size.height
#define WIDTH self.contentView.frame.size.width

@interface RecommendedCell ()

@end

@implementation RecommendedCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10 + (j * (10+((WIDTH - 40)/3))), 10 + (i * (10+((WIDTH - 40)/3))), (WIDTH - 40)/3, (WIDTH - 40)/3)];
            imageView.clipsToBounds = YES;
            imageView.layer.cornerRadius = 5;
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.userInteractionEnabled = YES;
            [self.contentView addSubview:imageView];
            imageView.tag = 320 + j + 3 * i;
            imageView.image = [UIImage imageNamed:@"NoPicture.jpg"];
            if (self.array.count != 0) {
                GoodsModel *model = [self.array objectAtIndex:j + 3 * i];
                [imageView sd_setImageWithURL:[NSURL URLWithString:model.photo_path]];
            }
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tiaozhuanhuidiao:)];
            [imageView addGestureRecognizer:tap];
        }
    }
    
}

- (void)tiaozhuanhuidiao:(UITapGestureRecognizer *)tap
{
    self.block([self.array objectAtIndex:(tap.view.tag - 320)]);
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
